<template>
    <Header/>
    <v-md-editor v-model="value" height="500px"></v-md-editor>

    <div class="collapse navbar-collapse" style="background-color: white;">
        <ul class="nav nav-pills navbar-nav">
                          
            <li>
                <p style="cursor: pointer;margin-right: 10px;" @click="upload">提交</p>
            </li>  
            <li>
                <p style="cursor: pointer;" @click="back">返回</p>
            </li>                  
        </ul>
    </div>

    <Footer/>
</template>

<script setup>
import { ref, getCurrentInstance, onMounted } from 'vue'
import { useRoute,useRouter } from 'vue-router'
import Header from "./Header.vue"
import Footer from "./Footer.vue"

const route = useRoute()
const router = useRouter()
const {proxy} = getCurrentInstance()
const value = ref('title:')

onMounted(()=>{
    if (route.params.id == 0){
        return
    }
    proxy.$http.post("/article",{
        id:route.params.id
    }).then(res =>{
        value.value = res.data.data.datahtml
    })
})

const back = ()=>{
    router.push({path:"/manager"})
}

const upload = () =>{
    console.log(route.params.id)
    proxy.$http.post("/manager",{
        token:localStorage.getItem("token"),
        datahtml:value.value,
        id:route.params.id

    }).then(res =>{
        if (res.data.status == 200 ){
            alert("提交成功")
            router.push({path:"/manager"})
        }else if (res.data.status == 400){
            alert("提交失败\n msg:" + res.data.msg)
        }else{
            alert("提交失败\n msg:" + res.data.msg)
            localStorage.setItem("isLogin",false)
            localStorage.setItem("token","")
            router.push({path:"/login"})
        }
    })
}
</script>